﻿using System;

namespace HB.HttpServer
{
    /// <summary>
    /// 【覆盖特性】自带基础权限验证，通过bit计算，含有32种权限
    /// </summary>
    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)]
    public class HttpLicense : Attribute
    {
        /// <summary>
        /// 用户可能含有多个角色的权限，使用bit记录，共有32种权限，0-31；
        /// </summary>
        int lic = 0;
        public HttpLicense(params int[] licenses)
        {
            int temp = 0;
            foreach (int offset in licenses)
            {
                if (offset < 32)
                {
                    int jt = 1 << offset;
                    temp = temp | jt;
                }
            }
            lic = temp;
        }
        public bool ContainLicense(int key)
        {
            return (key & lic) > 0;
        }
    }
}
